package com.ys.shop.dao;

import com.ys.shop.db.IDB;
import com.ys.shop.db.MySqlDBImp;
import com.ys.shop.vo.GoodType;
import com.ys.shop.vo.Users;
import com.ys.shop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GoodTypeDAOImp implements IDAO{
    @Override
    public boolean insert(VO vo) throws SQLException {
        return false;
    }

    @Override
    public List<VO> getAll() throws SQLException {
            PreparedStatement preparedStatement=null;
            ResultSet rs=null;
            List<VO> list=new ArrayList<VO>();
            IDB db=new MySqlDBImp();
            Connection conn=null;
            try {
                conn=db.getConn();
                String sql="select * from Easybuy_Product_Category";
                //得到数据库
                preparedStatement=conn.prepareStatement(sql);
                //获得结果集
                rs=preparedStatement.executeQuery();
                while (rs.next()){
                    GoodType u=new GoodType();
                    u.setEpc_id(rs.getInt(1));
                    u.setEpc_name(rs.getString(2));
                    u.setEpc_parent_id(rs.getInt(3));
                    list.add(u);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                db.closeAll(preparedStatement,rs,null);
            }
            return list;
        }

    @Override
    public boolean deleteByID(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean update(VO vo) throws SQLException {
        return false;
    }

    @Override
    public VO getByID(VO vo) throws SQLException {
        return null;
    }

    public static void main(String[] args) {
        GoodTypeDAOImp daoImp=new GoodTypeDAOImp();
        List listall=null;
        try {
            listall = daoImp.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
       System.out.println(((GoodType)listall.get(0)).getEpc_name());//取 get 放 add
    }
}
